layui.config({
    base: '../../layui/' //此处路径请自行处理, 可以使用绝对路径
}).extend({
    formSelects: 'formSelects-v4'
}).use(['jquery', 'formSelects', 'form','layer'], function () {
    var formSelects = layui.formSelects
        , form = layui.form
        , layer = layui.layer
        , $ = layui.jquery;

    formSelects.on('select1', function (id, vals, val, isAdd, isDisabled) {

    }, true);
    formSelects.data('tableName', 'server', {
        url: '/tableDesign/exportTableStructureExcelData',
        beforeSuccess: function (id, url, searchVal, result) {
            //我要把数据外层的code, msg, data去掉
            result = result.data;
            //然后返回数据
            return result;
        },
        success: function (id, url, searchVal, result) {
        }
    });
    form.render();

    form.on('submit(export)', function (data) {
        var params = {
            tableName: data.field.tableName
        }
        if (params.tableName.length==0){
            layer.msg("请选择要导出的表结构", {icon: 2, time: 3000})
            return false;
        }
        submit($, params);
        return false;
    });

    function submit($, params) {
        const  url = '/tableDesign/exportExcel';
        const form = $('<form></form>');
        form.attr('action', url + "?rand=" + Math.random());
        form.attr('method', 'post');
        for (const item in params) {
            const input = $('<input type="text" />');
            input.attr('name', item);
            input.attr('value', params[item]);
            form.append(input);
        }
        form.appendTo('body').submit().remove();
    }
    $("#del").on('click', function () {
        $.ajax({
            url: '/tableDesign/deleteOtherTable',
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            type: "POST",
            success: function (result) {
                layer.msg(result.data, {icon: 1, time: 3000}, function () {

                })
            }
        })
    });
});
